package edu.njfu.sas.util;

public class PageUtil {
    private  int CurrentPage;
    private long  totalRecords;
    private  int maxPage;
    private  int pageSize;

    public PageUtil(long  totalRecords, int pageSize,int CurrentPage) {
      this.totalRecords=totalRecords;
      this.pageSize=pageSize;
      this.maxPage=(int)(totalRecords%pageSize==0?(totalRecords/pageSize):(totalRecords/pageSize+1));
        setCurrentPage(CurrentPage);
    }
    /*
    *
    * 是否为第一页
    * */
   public  boolean isFirstPage(){
return  CurrentPage==1;
   }
   //是否为最后一页
    public  boolean isLastPage(){
      return  CurrentPage==maxPage;
    }
    //获取下一页
    public  int nextPage(){
       if(CurrentPage==maxPage){
           return maxPage;
       }else{
           return CurrentPage++;
       }

    }
    //获取上一页
    public int prevPage(){
        if(CurrentPage==1){
            return CurrentPage;
        }else{
            return CurrentPage--;
        }

    }
    public void setCurrentPage(int currentPage){
       if(currentPage>maxPage){
           this.CurrentPage=maxPage;
       }
        else if(currentPage<1){
           this.CurrentPage=1;
       }else{
            this.CurrentPage=currentPage;
       }
    }
    public int getcurrentPage(){
       return this.CurrentPage;
    }
    public  int getMaxPage(){
       return maxPage;
    }
}
